package com.jswzc.framework.util.emailUtil;

import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

/**
 * Created by DeathCat on 2017/05/12.
 */

public class ApacheMailUtil {


    public static String sendEmail(String addTo, String addFrom, String sub, String msg, String smtpType, String username, String password, int port) throws Exception{
        String res="T";
        try {
            Email email = new SimpleEmail();
            email.setHostName(smtpType);
            email.setSmtpPort(port);
            email.setAuthentication(username, password);
            email.setSSLOnConnect(true);
            email.setFrom(addFrom);
            email.setSubject(sub);
            email.setMsg(msg);
            email.addTo(addTo);
            email.send();
        } catch (EmailException e) {
            res=e.getMessage();
        }
        return res;
    }





}
